get gui map preview working with webengine.
authortsteven4 <tsteven4@gmail.com>
Sun, 3 Dec 2017 03:25:58 +0000 (20:25 -0700)
committertsteven4 <tsteven4@gmail.com>
Sun, 3 Dec 2017 03:25:58 +0000 (20:25 -0700)
gui/.gitignore
gui/app.pro
gui/gmapbase.html
gui/map.cc
gui/map.h

index 0b02c28d22c604b254dc661f43f8f69505d0f73d..bb7243608ccb0d1f215b2f080ab0bf8567e33b30 100644 (file)
@@ -4,3 +4,5 @@
 /makelinuxdist.sh
 /objects/
 /tmp/
+/release/
+/debug/
index 78761a06d80c9aa45bf06a879615c62288fcd5ee..335fc80288dbacc7ef0ad23c3be740eb1c784c9a 100755 (executable)
@@ -1,8 +1,10 @@
 # $Id: app.pro,v 1.19 2010-11-01 03:30:42 robertl Exp $
 #
 
-CONFIG += qt release 
-#CONFIG += qt debug console
+CONFIG += qt
+CONFIG(debug, debug|release) {
+  CONFIG += console
+}
 
 # For Mac, x86 and x64, but not PPC binary.   Ignored on other OSes.
 # macx:CONFIG -= x86_64 
index a85faa10132c5018698d03a16a0ec09637ea110e..39d008eb89e95d9c8cb8bbd2cad4328584138591 100644 (file)
@@ -7,7 +7,7 @@
     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAN6d3-kz3XqyJq-W9n7IYzhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxT_28W9HdpKXQF8sGkCU0sQpcudOQ"
       type="text/javascript"></script>
     <script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js">
-    </script>"
+    </script>
     <script type="text/javascript">
       var greenDotIcon = new GIcon();
       
 
 
       function load() {
-      if (GBrowserIsCompatible()) {
-        //var map = new GMap2(document.getElementById("map"));
-        //map.setCenter( new GLatLng(0,0), 2 );
-        //var mgr = new MarkerManager(map);
+         if (GBrowserIsCompatible()) {
+            if (typeof qt != 'undefined') {
+               new QWebChannel(qt.webChannelTransport, function(channel) { mclicker = channel.objects.mclicker; });
+            }
+         }
       }
-    }
                                  
 
     </script>
index 23cee4d703134207de8933287c5879154d7b124d..9ea04d665279e91da4858f5225c7ba8d1ddd7352 100644 (file)
@@ -69,7 +69,17 @@ Map::Map(QWidget *parent,
   manager_ = new QNetworkAccessManager(this);
   connect(this,SIGNAL(loadFinished(bool)),
          this,SLOT(loadFinishedX(bool)));
-  this->logTimeX("Start map constuctor");
+  this->logTime("Start map constuctor");
+
+#if HAVE_WEBENGINE
+  MarkerClicker *mclicker = new MarkerClicker(this);
+  QWebChannel* channel = new QWebChannel(this);
+  this->page()->setWebChannel(channel);
+  channel->registerObject(QStringLiteral("mclicker"), mclicker);
+  connect(mclicker, SIGNAL(markerClicked(int, int )), this, SLOT(markerClicked(int, int)));
+  connect(mclicker, SIGNAL(logTime(const QString &)), this, SLOT(logTime(const QString &)));
+#endif
+
   QString baseFile =  QApplication::applicationDirPath() + "/gmapbase.html";
   if (!QFile(baseFile).exists()) {
     QMessageBox::critical(0, appName,
@@ -90,7 +100,7 @@ Map::~Map()
 //------------------------------------------------------------------------
 void Map::loadFinishedX(bool f)
 {
-  this->logTimeX("Done initial page load");
+  this->logTime("Done initial page load");
   if (!f)
     QMessageBox::critical(0, appName,
                          tr("Failed to load Google maps base page"));
@@ -134,28 +144,23 @@ static QString fmtLatLng(const LatLng &l) {
 //------------------------------------------------------------------------
 void Map::showGpxData()
 {
+
+#if !defined(HAVE_WEBENGINE)
   MarkerClicker *mclicker = new MarkerClicker(this);
-#if HAVE_WEBENGINE
-  QWebChannel* channel = new QWebChannel(this);
-  this->page()->setWebChannel(channel);
-  channel->registerObject(QStringLiteral("mclicker"), mclicker);
-//  this->addToJavaScriptWindowObject("mclicker", mclicker);
-#else
   this->page()->mainFrame()->addToJavaScriptWindowObject("mclicker", mclicker);
-#endif
   connect(mclicker, SIGNAL(markerClicked(int, int )), this, SLOT(markerClicked(int, int)));
-  connect(mclicker, SIGNAL(logTime(const QString &)), this, SLOT(logTimeX(const QString &)));
-
+  connect(mclicker, SIGNAL(logTime(const QString &)), this, SLOT(logTime(const QString &)));
+#endif
   // It is appreciably faster to do the encoding on the C++ side.
   int numLevels = 18;
   double zoomFactor = 2;
   PolylineEncoder encoder(numLevels, zoomFactor, 0.00001);
 
 
-  this->logTimeX("Start defining JS string");
+  this->logTime("Start defining JS string");
   QStringList scriptStr;
   scriptStr
-    << "mclicker.logTime(\"Start JS execution\");"
+    << "mclicker.logTimeX(\"Start JS execution\");"
     << "var map = new GMap2(document.getElementById(\"map\"));"
     << "var bounds = new GLatLngBounds;"
     << "var waypts = [];"
@@ -169,7 +174,7 @@ void Map::showGpxData()
     << "var pn = map.getPane(G_MAP_MARKER_PANE);"
     << "pn.style.KhtmlUserSelect='none';"
     << "pn.style.KhtmlUserDrag='none';"
-    << "mclicker.logTime(\"Done prelim JS definition\");"
+    << "mclicker.logTimeX(\"Done prelim JS definition\");"
     << QString("var zoomFactor = %1;").arg(zoomFactor)
     << QString("var numLevels = %1;").arg(numLevels)
     ;
@@ -195,7 +200,7 @@ void Map::showGpxData()
     << "   GEvent.bind(waypts[i], \"click\", ftemp, ftemp.clicked);"
     << "   map.addOverlay(waypts[i]);"
     << "}"
-    << "mclicker.logTime(\"Done waypoints definition\");"
+    << "mclicker.logTimeX(\"Done waypoints definition\");"
     ;
 
   // Tracks
@@ -231,7 +236,7 @@ void Map::showGpxData()
     << "   bounds.extend(trkbound.getSouthWest());"
     << "   bounds.extend(trkbound.getNorthEast());"
     << "}"
-    << "mclicker.logTime(\"Done track definition\");"
+    << "mclicker.logTimeX(\"Done track definition\");"
     ;
 
   // Routes
@@ -263,17 +268,17 @@ void Map::showGpxData()
     << "   bounds.extend(rtebound.getSouthWest());"
     << "   bounds.extend(rtebound.getNorthEast());"
     << "}"
-    << "mclicker.logTime(\"Done route definition\");"
+    << "mclicker.logTimeX(\"Done route definition\");"
     ;
 
   scriptStr
     << "map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));"
-    << "mclicker.logTime(\"done setCenter\");"
+    << "mclicker.logTimeX(\"Done setCenter\");"
     ;
 
-  this->logTimeX("Done defining JS string");
+  this->logTime("Done defining JS string");
   evaluateJS(scriptStr);
-  this->logTimeX("Done JS evaluation");
+  this->logTime("Done JS evaluation");
 }
 
 //------------------------------------------------------------------------
@@ -288,7 +293,7 @@ void Map::markerClicked(int t, int i){
 }
 
 //------------------------------------------------------------------------
-void Map::logTimeX(const QString &s)
+void Map::logTime(const QString &s)
 {
   //  fprintf(stderr, "Log: %s:  %d ms\n", s.toStdString().c_str(), stopWatch.elapsed());
   if (textEdit_) {
index baa57e915f5e320240d3c77aa7f8de94167a2202..20dd949aa7f7761a65d481f5544cca565a13c16c 100644 (file)
--- a/gui/map.h
+++ b/gui/map.h
@@ -44,6 +44,9 @@ public slots:
   void clickedX(int t, int i) {
     emit markerClicked(t, i);
   }
+  void logTimeX(const QString &s) {
+    emit logTime(s);
+  }
 
 signals:
   void markerClicked(int t, int i);
@@ -87,7 +90,7 @@ class Map : public QWebView
   void frameTrack(int i);
   void frameRoute(int i);
 
-  void logTimeX(const QString &);
+  void logTime(const QString &);
   
  signals:
   void waypointClicked(int i);